﻿using System;
using System.Globalization;
using System.Windows.Data;
using DataClasses;

namespace CYPlayer.Converter
{
    class DoubleToTimeSpanConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var doubleSeconds = (double) value;
            var seconds = System.Convert.ToInt32(doubleSeconds);
            return Song.ConvertTotalSeconds(seconds);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var current = (TimeSpan)value;
            var intSeconds = Song.ConvertSpan(current);
            return System.Convert.ToDouble(intSeconds);
        }
    }
}
